<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8"/>
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>工作台</title>
  <link rel="stylesheet" href="/static/assets/libs/layui/css/layui.css"/>
  <link rel="stylesheet" href="/static/assets/module/admin.css?v=318"/>
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  <![endif]-->
  <style>
    .layui-form-label{
      width: 120px;
    }
  </style>
</head>
<body>
<!-- 正文开始 -->
<div class="layui-fluid ew-console-wrapper">
  <div class="layui-row layui-col-space15">
    <div class="layui-col-xs12">
      <div class="layui-card">
        <div class="layui-card-header">
          公告
        </div>
        <div class="layui-card-body">
          <form class="layui-form" action="">
            <div class="layui-form-item">
              <label class="layui-form-label">是否显示</label>
            <div class="layui-input-inline">
              <select name="val" lay-verify="required">
                <option value="1" <?php if($info['val'] == 1): ?>selected<?php endif; ?>>开启</option>
                <option value="0" <?php if($info['val'] == 0): ?>selected<?php endif; ?>>关闭</option>
              </select>
            </div>
            </div>
        
            <div class="layui-form-item">
              <label class="layui-form-label">图片</label>
              <div class="layui-input-inline">
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" id="upload-notice-img" src="{$info.img_url ?? ''}" style="width: 100%; height: 92px;">
                        <div>
                            <input type="hidden" id="img_url" name="img_url" value="{$info.img_url ?? ''}" />
                        </div>
                    </div>
               </div>
            </div>

            <div class="layui-form-item">
              <label class="layui-form-label">联系我们</label>
              <div class="layui-input-inline">
                <textarea name="content" placeholder="请输入内容" class="layui-textarea">{$info.content}</textarea>
              </div>
            </div>

            <div class="layui-form-item">
              <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即保存</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
              </div>
            </div>


          </form>
        </div>
      </div>
    </div>
  </div>
</div>
<!-- js部分 -->
<script type="text/javascript" src="/static/assets/libs/layui/layui.js"></script>
<script type="text/javascript" src="/static/assets/js/common.js?v=318"></script>
<script>
  layui.use(['layer','element','form', 'upload'], function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var upload = layui.upload;


    var uploadInst = upload.render({
        elem: "#upload-notice-img",
        url: "{:url('admin/main/uploadFile')}",
        before: function(obj) {
            obj.preview(function(index, file, result) {
                $("#upload-notice-img").attr("src", result);
            });
            
            layer.msg("上传中...", {icon: 16, time: 0});
        },
        done: function(res) {
            if(res.code != 200) {
                return layer.msg("上传失败");
            }
            
            $("#img_url").val(res.data.url);
            return layer.msg('上传成功');
        },
        error:function() {
            $("#upload-notice-img").on("click", function(){
                 uploadInst.upload();
            });
            return layer.msg("上传失败2");
        }
    });

    form.on('submit(formDemo)', function(data){
      $.post("{:url('admin/main/contactus')}", data.field, function (res) {
        if (res.code === 200) {
          layer.msg('保存成功', {icon: 1, time: 1500}, function () {
            location.reload()
          });
        } else {
          layer.msg(res.msg, {icon: 2, anim: 6});
        }
      }, 'json');
      return false;
    });
  });
</script>
</body>
</html>
